import { downloadFileFromBlobPart } from '@vben/utils'

import { requestClient } from '#/api/request'

/**
 * 获取采购收料
 */
export async function getRevicedRecordList(params: any) {
  return requestClient.get('/admin/RevicedRecord/index', params)
}

/**
 * 获取采购收料
 */
export async function getRevicedRecordDetailEditInfo(params: any) {
  return requestClient.get('/admin/RevicedRecord/edit', params)
}


/**
 * 收料记录
 */
export async function getRevicedLog(params: any) {
  return requestClient.post('/admin/PurchaseBomDetail/getRevicedLog', params)
}

/**
 * 物料添加
 */
export async function doRevicedRecordAdd(params: any) {
  return requestClient.post('/admin/RevicedRecord/add', params,{responseReturn:"raw"});
}

/**
 * 物料编辑
 */
export async function doRevicedRecordEdit(params: any) {
  return requestClient.post('/admin/RevicedRecord/edit', params, { responseReturn: 'raw' })
}

/**
 * 物料删除
 */
export async function doRevicedRecordDelete(params: any) {
  return requestClient.post('/admin/RevicedRecord/del', params);
}

/**
 * 物料审核
 */
export async function doRevicedRecordApproval(params: any) {
  return requestClient.post('/admin/RevicedRecord/approval', params);
}

/**
 * 反审
 */
export async function doRevicedRecordAgainst(params: any) {
  return requestClient.post('/admin/RevicedRecord/against', params);
}


/**
 * 导出
 */
export async function exportExpiredData(params: any) {
  const res = await requestClient.post('/admin/RevicedRecord/index', {...params,is_exp:true}, {
    responseType: 'blob', // 设置响应类型为 blob
    responseReturn: 'raw', // 返回原始响应而不是解析后的数据
  })

  const blob = new Blob([res.data], {
    type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  })
  downloadFileFromBlobPart({
    source: blob,
    fileName: '生产面辅料逾期情况.xlsx',
  })
}


/**
 * 物料
 */
export async function getSkuList(params: any) {
  return requestClient.post('/admin/purchase/getPurchaseBomList', params);
}

